

import java.util.*;
import Connectivity.*;
import java.sql.*;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

/*
* this class generates one pdf file from jaspar file. here i used one condition that filter
* only first 30 records.
* author: rajib_info@yahoo.com
*/

public class ClientList {

public static void main(String[] args) {
// database connection
Connection connection = null;

String jasperFile = "/clist.jasper";
String pdfFile = "/clist.pdf";

// params used for passing the parameter.
HashMap params = new HashMap();
params.put("p_id","30");
try {
// get database connection.
connection = ConnectionManager.getConnection();

JasperPrint print = JasperFillManager.fillReport(jasperFile, params,
connection);
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,
pdfFile);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.exportReport();
System.out.println("Created file: " + pdfFile);

} catch (JRException e) {
e.printStackTrace();
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}

